<?php

	class PartnerSubscriber extends Model_Abstract
	{
		public function addNewRegUser($uid)
		{
			$sql = " INSERT INTO partner_subscriber SET user_id=? ";
			try{
				return $this->_connection->execute($sql, array( $uid ));
			}catch(Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getUnSubUsers()
		{
			$sql = " SELECT user_id FROM partner_subscriber WHERE status='unsub' AND unsub_date='0000-00-00' ";
			try{
				$result = $this->_connection->query($sql);
				if(!empty($result)){
					foreach($result as $k=>$v){
						$result[$k] = $v['user_id'];
					}	
				}
				return $result;
			}catch(Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function setUnsub_date($usersId)
		{
			$sql = " UPDATE partner_subscriber SET unsub_date=? WHERE user_id IN ( " . implode(', ', $usersId) . " ) ";
			try{
				return $this->_connection->execute($sql, array( date('Y-m-d') ));
			}catch(Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
	}